/**
 * option指令
 */
module.exports = angular.module('directive.uiOption', []).directive('uiOption',function() {
    return {
        template: '<li role="menuitem"  data-option-val="{{value}}" ng-transclude></li>',
        replace: true,
        require:'^uiSelect',
        scope: {
            value: '='
        },
        link:function (scope,el,attrs,uiSelectCtl) {
            //从父指令传值比较
            if(attrs.optionVal == uiSelectCtl.val()){
                var text = $(el).text()
                //用笨方法去实现循环时获取,因为此的时name拿不到
                console.log(text);
                text=text.replace(/^\s+|\s+$/g,"");//去除字符串两端的空格
                console.log(text);
                var _item = text.substring(2,text.indexOf('.'))
                var _name = text.substring(text.indexOf('.')+1,text.length-2)
                console.log(_item);
                console.log(_name);
                scope.$emit('value', {
                    value:attrs.optionVal,
                    name:text.indexOf('{{') > -1?scope.$parent[_item][_name]:$(el).text()
                });
            }

            $(el).on('click',function (ev) {
                var val =$(this).attr('data-option-val')
                scope.$emit('value', {value:val,name:$(this).text()});
            })
        },
        transclude:true

    }
}).name